local skill = fk.CreateSkill {
  name = "#chixiao_sword_skill",
  attached_equip = "chixiao_sword",
}

Fk:loadTranslationTable {
  ["#chixiao_sword_skill"] = "赤霄剑",
  ["#chixiao_sword_skill-invoke"] = "赤霄剑：你可以弃置两张牌（不足全弃，无牌不弃），摸两张牌",
}

local spec = {
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local ids = table.filter(player:getCardIds("he"), function(id)
      return not player:prohibitDiscard(id)
    end)
    if #ids <= 2 then
      if room:askToSkillInvoke(player, {
        skill_name = skill.name,
        prompt = "#chixiao_sword_skill-invoke"
      }) then
        event:setCostData(self, {cards = ids})
        return true
      end
    else
      local cards = room:askToDiscard(player, {
        min_num = 2,
        max_num = 2,
        include_equip = true,
        skill_name = skill.name,
        cancelable = true,
        prompt = "#chixiao_sword_skill-invoke",
        skip = true,
      })
      if #cards > 0 then
        event:setCostData(self, {cards = cards})
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #event:getCostData(self).cards > 0 then
      room:throwCard(event:getCostData(self).cards, skill.name, player, player)
    end
    if not player.dead then
      player:drawCards(2, skill.name)
    end
  end,
}

skill:addEffect(fk.TargetSpecified, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skill.name) and data.card.trueName == "slash" and data.firstTarget
  end,
  on_cost = spec.on_cost,
  on_use = spec.on_use,
})

skill:addEffect(fk.TargetConfirmed, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skill.name) and data.card.trueName == "slash"
  end,
  on_cost = spec.on_cost,
  on_use = spec.on_use,
})

return skill
